#include "zhutest.h"
#include <QHostAddress>
#include <QDebug>
#include <QtCore>

zhuTest::zhuTest(QObject *parent):
    QObject(parent)
{


    this->isconnetion = false;
    this->TCP_sendMesSocket = new QTcpSocket();
    TCP_sendMesSocket->abort();
    this->TCP_sendMesSocket->connectToHost("192.168.119.131",8888); //连接１９２．１６８．１１９．１３１
    connect(TCP_sendMesSocket,SIGNAL(connected()),this,SLOT(slot_connected()));
}


void zhuTest::slot_connected()
{
    this->isconnetion = true;
    qDebug() <<"连接成功";
  // getDetialList();
  //getTodayTemperature();
    //QString obj ="连接成功";
   // emit sendconnected(obj);

}

void zhuTest::slot_recvmessage()
{
    QByteArray byteArray = this->TCP_sendMesSocket->readAll();
    QJsonObject json =QJsonObject(QJsonDocument::fromJson(byteArray).object());
    qDebug() << json;

    //qDebug() <<json.take("time").toString();

    emit sendTodayTemperature(json);
    TCP_sendMesSocket->deleteLater();

}

//void zhuTest::slot_recvmessages()
//{
//    QByteArray byteArray = this->TCP_sendMesSocket->readAll();
//    QJsonArray json1 =QJsonArray(QJsonDocument::fromJson(byteArray).array());
//    qDebug() << json1;

//    //qDebug() <<json.take("dayName").toString();

//    emit sendDetialList(json1);
//    TCP_sendMesSocket->deleteLater();

//}
//void zhuTest::slot_recvmessages1()
//{
//    QByteArray byteArray = this->TCP_sendMesSocket->readAll();
//    QJsonArray json2 =QJsonArray(QJsonDocument::fromJson(byteArray).array());
//    qDebug() << json2;

//    //qDebug() <<json.take("dayName").toString();

//    emit senchartData(json2);

//    TCP_sendMesSocket->deleteLater();
//}

void zhuTest::getTodayTemperature()
{
    this->TCP_sendMesSocket->write("allData");
    connect(TCP_sendMesSocket,SIGNAL(readyRead()),this,SLOT(slot_recvmessage()));

}

//void zhuTest::getDetialList()
//{
//    QString str ="DetialList";
//    str +=\r;
//    this->TCP_sendMesSocket->write(str.toLatin1());
//    connect(TCP_sendMesSocket,SIGNAL(readyRead()),this,SLOT(slot_recvmessages()));

//}
//void zhuTest::getchartData()
//{
//    QString str ="chartData";
//    str +=\r;
//    this->TCP_sendMesSocket->write(str.toLatin1());
//    connect(TCP_sendMesSocket,SIGNAL(readyRead()),this,SLOT(slot_recvmessages1()));

//}
